package com.muyu.product.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.RuleInfoAddModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.annotation.Excel;
import com.muyu.product.domain.req.RuleInfoQueryReq;
import com.muyu.product.domain.req.RuleInfoSaveReq;
import com.muyu.product.domain.req.RuleInfoEditReq;
import com.muyu.common.core.web.domain.BaseEntity;

import java.util.Date;
import java.util.function.Supplier;

/**
 * 商品规格对象 rule_info
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("rule_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "RuleInfo", description = "商品规格")
public class RuleInfo extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /** 主键 */
    @TableId(value = "id",type = IdType.AUTO)
    @ApiModelProperty(name = "主键", value = "主键")
    private Long id;

    /** 规格名称 */
    @Excel(name = "规格名称")
    @ApiModelProperty(name = "规格名称", value = "规格名称")
    private String name;

    /** 规格状态 */
    @Excel(name = "规格状态")
    @ApiModelProperty(name = "规格状态", value = "规格状态")
    private String status;

    /**
    * 查询构造器
    */
    public static RuleInfo queryBuild( RuleInfoQueryReq ruleInfoQueryReq){
        return RuleInfo.builder()
                .name(ruleInfoQueryReq.getName())
                .status(ruleInfoQueryReq.getStatus())
                .build();
    }

    /**
    * 添加构造器
    */
    public static RuleInfo saveBuild(RuleInfoSaveReq ruleInfoSaveReq){
        return RuleInfo.builder()
                .name(ruleInfoSaveReq.getName())
                .status(ruleInfoSaveReq.getStatus())
                .build();
    }

    /**
    * 修改构造器
    */
    public static RuleInfo editBuild(Long id, RuleInfoEditReq ruleInfoEditReq){
        return RuleInfo.builder()
            .id(id)
                .name(ruleInfoEditReq.getName())
                .status(ruleInfoEditReq.getStatus())
                .build();
    }

    /**
     *
     * @param ruleInfoAddModel 添加模型
     * @param createBy 创建者
     * @return 规格对象
     */
    public static RuleInfo addModelBuild (RuleInfoAddModel ruleInfoAddModel, Supplier<String> createBy) {
        return RuleInfo.builder()
                .name(ruleInfoAddModel.getName())
                .status(ruleInfoAddModel.getStatus())
                .createBy(createBy.get())
                .createTime(new Date())
                .build();
    }
}
